package com.luo.locationapp.activity;

import com.luo.locationapp.R;
import com.luo.locationapp.global.CustomValue;
import com.luo.locationapp.global.GlobalContents;
import com.luo.locationapp.interfaces.impl.GeneralProcessorInterfaceImpl;
import com.luo.locationapp.link.LinkServiceTask;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

	private EditText edt_id,edt_password;
	private Button bt_clear,bt_login,bt_register;
	private TextView tv_register;
	private DisplayMetrics metric;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		//startActivity(new Intent(this, AddFootmarkActivity.class));
		init();
		initListener();
//		String returnJson = "{\"returnCode\":\"0\",\"message\":\"��¼�ɹ���\",\"currentUser\":{\"comments\":\"����\",\"createtime\":\"2014-09-16 14:24:41.0\",\"id\":\"00000000\",\"name\":\"����Ա\",\"password\":\"000000\"}}";
//		loginTransfer(CustomJsonUtils.getAttributeByName(returnJson, "currentUser"));
	}


	
	private void init(){
		edt_id = (EditText) findViewById(R.id.user_id);
		edt_password = (EditText) findViewById(R.id.user_password);
		bt_clear = (Button) findViewById(R.id.login_clear);
		bt_login = (Button) findViewById(R.id.login_submit);
		tv_register = (TextView) findViewById(R.id.login_register);
		
		metric = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metric);
		
		edt_id.setWidth((int) (metric.widthPixels * 0.8));
		edt_password.setWidth((int) (metric.widthPixels * 0.8));
		
		//ȫ�ֱ�����ʼ��
		GlobalContents.screen_width = metric.widthPixels;
		GlobalContents.screen_height = metric.heightPixels;
		
	}

	private void initListener() {
		bt_clear.setOnClickListener(this);
		bt_login.setOnClickListener(this);
		tv_register.setOnClickListener(this);
	}
	@Override
	protected void onStart() {
		super.onStart();
		
		AnimationSet animationSet = new AnimationSet(true);
		animationSet.addAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.translateup));
		animationSet.addAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha));
		findViewById(R.id.ll_dialog).startAnimation(animationSet);
		findViewById(R.id.ll_operate).startAnimation(animationSet);
		
	}
	@Override
	public void onClick(View arg0) {
		switch(arg0.getId()){
		case R.id.login_register:
			startActivityForResult(new Intent(MainActivity.this, RegisterActivity.class), CustomValue.RESULT_CODE_REGISTER_RETURN);
			break;
		case R.id.login_clear:
			edt_id.setText("");
			edt_password.setText("");
			break;
		case R.id.login_submit:
			new LinkServiceTask(MainActivity.this, new GeneralProcessorInterfaceImpl(MainActivity.this)).execute("login", edt_id.getText().toString()+";"+edt_password.getText().toString());
			break;
		}
	}
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
}
